﻿using B.S.BasicData.ErrorCode;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace B.S.BasicData.Api.Read.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class UploadController : ControllerBase
    {

        /// <summary>
        /// 图片上传接口
        /// </summary>
        /// <param name="file"></param>
        /// <returns></returns>
        [HttpPost]
        public ApiResult<string> Img(IFormFile file) {

            var dir =Directory.GetCurrentDirectory()+@"/wwwroot/pic/"+file.FileName;
            using (FileStream fs = new FileStream(dir,FileMode.Create))
            {
                file.CopyTo(fs);
                fs.Close();
            }

            return new ApiResult<string> (){  Code=ApiEnum.Success,Msg="图片上传成功", Data = "http://localhost:5141/pic/"+file.FileName };
        }
    }
}
